package messageDao

import (
	"chart.zozoo.net/app/models"
	"chart.zozoo.net/core/mysql"
	"errors"
	"gorm.io/gorm"
)

// FindByMsgId 根据消息id获取消息列表
func FindByMsgId(msgId string, offset, limit int) (list []*models.Message, err error) {
	list = make([]*models.Message, 0)
	res := mysql.MysqlClient.Where("msg_id=?", msgId).
		Select("from_uid,to_uid,msg_type,msg_content,created_at").
		Order("id desc").
		Offset(offset).
		Limit(limit).
		Find(&list)
	if res.Error != nil && !errors.Is(res.Error, gorm.ErrRecordNotFound) {
		return nil, res.Error
	}
	return
}
